<?php

namespace app\framework\lib;
use think\facade\Db;
use Workerman\Timer;

class Mysql
{
// 进程启动时调用
    public static function start($worker)
    {
        // 配置
        $config = Config::getInstance()->db;
        Db::setConfig($config);
        Db::setLog(new MonologHandler());
        // 维持mysql心跳
        if ($worker) {
            Timer::add(55, function () use ($config) {
                $connections = $config['connections'];
                foreach ($connections as $key => $item) {
                    if ($item['type'] == 'mysql') {
                        Db::connect($key)->query('select 1');
                    }
                }
            });
        }
    }
}